package com.my.kq.dao;

import com.my.kq.entity.Leave;
import com.my.kq.uitl.BaseDAO;

import java.util.List;

public class LeaveDao extends BaseDAO {

    public List<Leave> leavelist(Integer num) throws Exception {
        String sql = "select * from lea where employeeNumber=?";
        Object[] obj = {num};
        return getList(sql,new Leave(),obj);
    }
    //根据当前页查询已批准数据
    public List<Leave> getPage(int pageNo,String status) throws Exception {
        String sql="select * from lea where status=?  limit ?,?";
        //本次每页给5行数据显示
        Object[]obj={status,(pageNo-1)*5,5};
        List<Leave> list = getList(sql, new Leave(), obj);
        return list;
    }
    //查询已批准数据总条数
    public int getTotal(String status) throws Exception {
        String sql="select count(1) from lea where status=?";
        Object[]obj={status};
        int count = getCount(sql, obj);
        return count;
    }

    //查询当前页所有  已批准+未批准
    public List<Leave> getPageAll(int pageNo) throws Exception {
        String sql="select * from lea limit ?,?";
        Object[]obj={(pageNo-1)*5,5};
        List<Leave> list = getList(sql, new Leave(), obj);
        return list;
    }

    public int leaveadd(Integer number, String start, String end, String type, String reason, int tshu) throws Exception {
        String sql = "insert into lea values(null,?,null,?,?,?,?,?,null,?,null)";
        String ss="未批准";
        Object[] obj = {number, start, end, tshu, type, reason,ss};
        int i = addOrupdOrdel(sql, obj);

        return i;
    }
    public int getTotalALL() throws Exception {
        String sql="select count(1) from lea";
        Object[]obj={};
        int count = getCount(sql, obj);
        return count;
    }
    public void setAgree(int id) throws Exception {
        String sql="update lea set status=? where id=?";
        Object[]obj={"已批准",id};
        addOrupdOrdel(sql,obj);
    }

    //通过id获取Leave
    public Leave getLeaveById(int id) throws Exception {
        String sql="select * from lea where id=?";
        Object[]obj={id};
        Leave one = getOne(sql, new Leave(), obj);
        return one;
    }
}
